main
 1---
 2import { getCollection, render } from "astro:content";
 3import type { GetStaticPaths, InferGetStaticPropsType } from "astro";
 4
 5import { SITE_CONFIG } from "@/config.ts";
 6import BaseLayout from "@/layouts/BaseLayout.astro";
 7import { getPostsLocaleMap } from "@/utils/content.ts";
 8import { getLocaleRouteParam } from "@/utils/url.ts";
 9import "@/styles/article/index.scss";
10
11type Props = InferGetStaticPropsType<typeof getStaticPaths>;
12
13export const getStaticPaths = (async () => {
14  const posts = await getCollection("posts");
15  const postsLocaleMap = getPostsLocaleMap(posts);
16
17  return Object.entries(postsLocaleMap).flatMap(([slug, localeMap]) => {
18    const availableLocales = SITE_CONFIG.locales.filter(
19      (locale) => localeMap[locale] !== undefined,
20    );
21
22    return SITE_CONFIG.locales
23      .map((locale) => {
24        const entry = localeMap[locale];
25        if (entry === undefined) {
26          return undefined;
27        } else {
28          return {
29            params: { locale: getLocaleRouteParam(locale), slug },
30            props: { entry, availableLocales },
31          };
32        }
33      })
34      .filter((i) => i !== undefined);
35  });
36}) satisfies GetStaticPaths;
37
38const { entry, availableLocales } = Astro.props;
39
40const data = entry.data;
41const { Content } = await render(entry);
42---
43
44<BaseLayout
45  title={data.title}
46  author={data.author}
47  description={data.desc}
48  availableLocales={availableLocales}
49  ogType="article"
50>
51  <article>
52    <Content />
53    <footer>
54      <small>
55        <p>
56          License:
57          {typeof data.license === "string" ? (
58            data.license
59          ) : (
60            <a href={data.license.link}>{data.license.name}</a>
61          )}
62        </p>
63      </small>
64    </footer>
65  </article>
66</BaseLayout>